package cn.yunhe.service.impl;

import cn.yunhe.dao.IProductDao;
import cn.yunhe.pojo.Product;
import cn.yunhe.service.IProductService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    IProductDao productDao;

    Product product;

    public List<Product> queryAll(Product product, Integer pageIndex, Integer pageSize) {
        if(product == null){
            product = new Product();
        }
        //使用PageHelper分页插件
        PageHelper.startPage(pageIndex, pageSize);
        return productDao.queryAll(product);
    }

    public void insertProduct(Product product) {
        //程序员自己维护一个UUID作为产品id
        String replace = UUID.randomUUID().toString().replace("-", "");
        product.setId(replace);
        productDao.insertProduct(product);
    }
}
